<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');
session_start();

class test extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->library('session');
		$this->load->helper('url');
		$this->load->library('upload');
		$this->load->library('pagination');
		$this->load->library('parser');
		$this->load->helper('cookie');
		$this->upload->set_allowed_types('*');
		$this->load->helper(array('form', 'url'));
		@session_start();
	}

	public function post2(){
		$url = "http://appstore.vn/android/home/pcdownload'";
		$data = array('versionid' => '72855', 'appid'=>'21385','link_type'=>'fshare.vn');

		//url-ify the data for the POST
		foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
		rtrim($fields_string,'&');

		//open connection
		$ch = curl_init();

		//set the url, number of POST vars, POST data
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_POST,count($data));
		curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

		//execute post
		$result = curl_exec($ch);
		print $result;
	}
	public function post(){
		$url = 'http://appstore.vn/android/home/pcdownload';
		$data = array('versionid' => '72855', 'appid'=>'21385','link_type'=>'fshare.vn');

		// use key 'http' even if you send the request to https://...
		$options = array(
		    'http' => array(
		        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
		        'method'  => 'POST',
		        'content' => http_build_query($data),
		    ),
		);
		$context  = stream_context_create($options);
		$result = file_get_contents($url, false, $context);

		echo "<pre>";
		var_dump($result); 
		echo "</pre>";
	}

	public function index() { 
		$postData = array(
			'versionid' => 'versionid',
			'appid' => '21385', 
			'link_type' =>'fshare.vn',
		); 
		$ch = curl_init('http://appstore.vn/android/home/pcdownload');
		curl_setopt_array($ch, array(
			CURLOPT_POST => TRUE,
			CURLOPT_RETURNTRANSFER => TRUE,
			CURLOPT_HTTPHEADER => array(
				'Authorization: '.'nPh9NyFGaUUbWUMCQipd3A',
				'Content-Type: application/json'
			),
			CURLOPT_POSTFIELDS => json_encode($postData)
		));

		// Send the request
		$response = curl_exec($ch);

		// Check for errors
		if($response === FALSE){
			die(curl_error($ch));
		}

		// Decode the response
		$responseData = json_decode($response, TRUE);

		// Print the date from the response
		echo "<pre>";
		var_dump($responseData); die();
		echo "</pre>";
// 		$direct =  shell_exec("php app/15/test.php Tuvi.apk");
// 		echo $direct;

// 		$string1 = shell_exec('aapt dump badging app/15/Tuvi.apk');

// 		echo "<pre>";
// 		$arr = explode(" ", $string1);
// 		print_r($arr);
// 		echo "</pre>";

// 		echo "<br/>";
		/*$output = exec('java -jar ./app/15/apktool.jar d -f ./app/15/Tuvi.apk');
		echo $output;
		echo "<pre>";
		die();
		$arr = explode(" ", $output);
		print_r($arr);
		echo "</pre>"; */
		
		


	}
}
